from hide_info import mirage_tank
import tkinter as tk
from tkinter import filedialog, messagebox

def select_file(title):
    return filedialog.askopenfilename(title=title, filetypes=[("Image files", "*.png;*.jpg;*.jpeg")])

def save_file():
    return filedialog.asksaveasfilename(title="保存幻影坦克图片", defaultextension=".png", filetypes=[("PNG files", "*.png")])

def process_images():
    img1_path = img1_entry.get()
    img2_path = img2_entry.get()
    output_path = output_entry.get()
    
    if not all([img1_path, img2_path, output_path]):
        status_label.config(text="错误: 请选择所有图片并指定输出路径")
        return
    
    try:
        mirage_tank.mirage_tank(img1_path, img2_path, output_path)
        status_label.config(text="成功: 幻影坦克图片已生成！", fg="green")
    except Exception as e:
        status_label.config(text=f"错误: {str(e)}", fg="red")

# 创建主窗口
root = tk.Tk()
root.title("幻影坦克生成器")
root.geometry("400x350")

# 创建UI组件
tk.Label(root, text="图片1:").pack()
img1_entry = tk.Entry(root, width=40)
img1_entry.pack()
tk.Button(root, text="选择图片1", command=lambda: img1_entry.insert(0, select_file("选择图片1"))).pack()

tk.Label(root, text="图片2:").pack()
img2_entry = tk.Entry(root, width=40)
img2_entry.pack()
tk.Button(root, text="选择图片2", command=lambda: img2_entry.insert(0, select_file("选择图片2"))).pack()

tk.Label(root, text="输出路径:").pack()
output_entry = tk.Entry(root, width=40)
output_entry.pack()
tk.Button(root, text="选择输出路径", command=lambda: output_entry.insert(0, save_file())).pack()

tk.Button(root, text="生成幻影坦克", command=process_images).pack(pady=20)

# 状态标签
status_label = tk.Label(root, text="", fg="red")
status_label.pack(pady=10)

root.mainloop()